from selenium import webdriver
import time
from selenium.webdriver.common.by import By

# 打开Edge浏览器
driver = webdriver.Edge()
# 进入酒仙网
driver.get('https://www.jiuxian.com/')
# 窗口最大化
driver.maximize_window()
# 点击请登录
driver.find_element(By.CLASS_NAME, 'headerLogin').click()
# 输入用户名
driver.find_element(By.ID, 'userName').send_keys('15523615751')
# 输入密码
driver.find_element(By.ID, 'password').send_keys('lj070130.')
time.sleep(15)
# 点击登录
driver.find_element(By.NAME, 'bi_Usuallogin').click()
time.sleep(3)
# 弹窗确定
driver.find_element(By.ID, 'bindSub').click()
time.sleep(3)
# 登陆成功,文本断言
dy = driver.find_element(By.XPATH, '/html/body/div[2]/div/div[1]/div/p/span').text
print(dy)
assert "jxw862943923" == dy
# 点击输入框下的五粮液
driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/p/a[2]').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(3)
# 五粮液酒品列表,文本断言
dy2 = driver.find_element(By.XPATH, '/html/body/div[6]/div/div[2]/div[2]/div/a/span[1]').text
print(dy2)
assert '五粮液' in dy2
# 选择第一排任意商品
driver.find_element(By.XPATH, '/html/body/div[6]/div/div[2]/div[6]/ul/li[5]/div[2]/div[1]/a/img').click()
driver.switch_to.window(driver.window_handles[-1])
time.sleep(3)
# 商品单价，文本断言
dy3 = driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[3]/div[2]/div[2]/span[1]/strong').text
print(dy3)
assert '39.00' == dy3
# 数量增加为2
driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[2]/div[6]/div[4]/div[2]/div[1]/a[1]').click()
time.sleep(2)
# 点击加入购物车
driver.find_element(By.ID, 'addToCartForDetail').click()
time.sleep(2)
# 查看购物车
driver.find_element(By.NAME, 'detail_chakangouwuche').click()
time.sleep(2)
# 进入购物车，断言我的购物车  1
dy4 = driver.find_element(By.CLASS_NAME, 'my-cart-tit').text
print(dy4)
assert '我的购物车' in dy4
# 点击去结算
driver.find_element(By.CLASS_NAME, 'done').click()
time.sleep(3)
# 断言收货人
dy5 = driver.find_element(By.XPATH, '/html/body/div[3]/div/div[1]/div[2]/ul/li/div[1]/span[1]').text
print(dy5)
assert '小刘' == dy5
# 选择支付方式，文本断言
dy6 = driver.find_element(By.XPATH, '/html/body/div[3]/div/div[2]/div[1]/h3').text
print(dy6)
assert '选择支付方式' == dy6
# 点击提交订单
driver.find_element(By.ID, 'submitOrder').click()
time.sleep(3)
# 断言金额
dy7 = driver.find_element(By.XPATH, '/html/body/div[4]/div/div[1]/ul/li[3]/b').text
print(dy7)
assert "￥88.00" == dy7
# 断言 订单编号
dy8 = driver.find_element(By.XPATH,'/html/body/div[4]/div/div[1]/ul/li[3]/em').text
print(dy8)
assert '17250602' in dy8